Skip to content

Fix Expression Formatter#217

Open
rcosta358 wants to merge 4 commits intomainfrom
fix-expression-formatter
Open

Fix Expression Formatter#217
rcosta358 wants to merge 4 commits intomainfrom
fix-expression-formatter

Conversation

@rcosta358
Copy link
Copy Markdown
Collaborator

Description

This PR fixes the ExpressionFormatter so grouped expressions only have parentheses when needed for precedence or associativity. This simplifies expressions in the error messages and in the context debugger.

Example

Before and after:

  • (1)1
  • (a > 0)a > 0
  • a && (b > 0)a && b > 0

Unchanged cases:

  • a - (b + c)
  • x == (1 > 0)
  • !(x > 0)

Related Issue

None.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring

Checklist

  • Added/updated in ExpressionFormatterTest
  • mvn test passes locally
  • Updated docs/README if behavior or API changed

@rcosta358 rcosta358 requested a review from CatarinaGamboa May 10, 2026 13:40
@rcosta358 rcosta358 self-assigned this May 10, 2026
@rcosta358 rcosta358 added error messages Related to error messages enhancement New feature or request labels May 10, 2026
Copy link
Copy Markdown
Collaborator

@CatarinaGamboa CatarinaGamboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the ite grouped expressions, maybe the --> as well. They would pass the parser correctly but its harder for developers to easily see the right associative rule - at least for me it is, what do you think?

assertEquals("(a ? b : c) ? d : e",
new Ite(new GroupExpression(ite), new Var("d"), new Var("e")).toDisplayString());
assertEquals("a ? b : (c ? d : e)",
assertEquals("a ? b : c ? d : e",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in here I think we want the parenthesis to still be there, right? reading it, it could either be
a ? b : c ? d : e
a) a ? b : (c ? d : e)
b) (a ? b : c) ? d : e
Also we can improve the tree construction as well, but you can do that in a followup PR

@rcosta358
Copy link
Copy Markdown
Collaborator Author

I think it's understandable without the parentheses but I get your point.
Will change it.

@rcosta358 rcosta358 requested a review from CatarinaGamboa May 11, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request error messages Related to error messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants